<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>go page top</title>
  <style>
    #scrollDiv {
      background-color: #ccc;
      height: 300px;
      overflow-y: auto;
      position: relative;
    }

    div.block {
      width: 10px;
      height: 3000px;
      background-color: red;
    }

    div.top-botton {
      --size: 50px;
      width: var(--size);
      height: var(--size);
      line-height: var(--size);

      background-color: white;
      text-align: center;

      position: absolute;
      top: 222px;
      right: 60px;

      cursor: pointer;
    }
  </style>
</head>

<body>
  <div id="scrollDiv">
    <div class="block"></div>
    <div class="block"></div>
    <div class="block"></div>
  </div>
  <div class="top-botton">Top</div>

  <script src="./index.js"></script>
  <script>
    const scrollDiv = document.querySelector('#scrollDiv');
    const topBotton = document.querySelector('.top-botton');

    topBotton.addEventListener('click', () => {
      goTop(scrollDiv);
    });
  </script>
</body>

</html>